//reduce  数字数组求和
let arr = [100, 200, 300, 400];

arr.reduce((total, item, index, arr) => {
  // console.log(total, item, index, arr);
}, 0);

let result = arr.reduce((total, item) => {
  // return total = total + item;
  return (total += item);
  // return total;
}, 10);

result = arr.reduce((total, item) => {
  // return total = total + item;
  return (total += item);
  // return total;
});
console.log(result);

//对象数组
// let arr = [
//   { id: 1, name: "孙悟空", weight: 70 },
//   { id: 2, name: "猪八戒", weight: 80 },
//   { id: 3, name: "黑熊精", weight: 200 },
//   { id: 4, name: "唐僧", weight: 120 },
// ];


// // let result = arr.reduce((total, item, index, arr) => {
// //   // console.log(total)
// //   total = total + item.weight;
// //   return total;
// // }, 0);

// let result = arr.reduce((total, item, index, arr) => {
//   // console.log(total)
//   total = total + item.weight;
//   return total;
// });
// console.log(result)



//recude 浅拷贝
